<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>市平台财务统计管理</title>
<meta name="decorator" content="default" />
<script src="${ctxStatic}/common/format/formatDate.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		/* $("#area").click(function() {
			var url = "${ctx }/area/areaChoose/areaQu";
			layer.open({
				type : 2,
				title : '',
				shadeClose : true,
				shade : 0.8,
				area : [ '800px', '500px' ],
				content : url
			});
		}); */
		var now = new Date(); //当前日期
		var nowMonth = now.getMonth(); //当前月
        var nowYear = now.getYear(); //当前年
        nowYear += (nowYear < 2000) ? 1900 : 0;
        var oldYear = nowYear-1;     //上一年
		$(document).on("click","#lastMonth",function(){
			debugger;
			var startDate = new Date($("#startDate").val());
			startDate.setMonth(startDate.getMonth()-1);
	        var firstDate = getLastMonthFirstDay(startDate);
			var lastDate = getLastMonthLastDay(startDate);
	        $("#startDate").val(firstDate);
			$("#endDate").val(lastDate);
		})
		$(document).on("click","#thisYear",function(){
			debugger;
			var startDate = new Date($("#startDate").val());
			var firstDate = getFirstDayOfYear(startDate);
			var lastDate = getLastDayOfYear(startDate);
			$("#startDate").val(firstDate);
			$("#endDate").val(lastDate);
		})
		$(document).on("click","#thisMonth",function(){
			var firstDate = getThisMonthFirstDay(now);
			var lastDate = getThisMonthNowDay(new Date());
			$("#startDate").val(firstDate);
			$("#endDate").val(lastDate);
		})
		$(document).on("click","#quarter",function(){
			debugger;
			var startDate = new Date($("#startDate").val());
			var firstDate = getQuarterFirstDay(startDate);
			var lastDate = getQuarterLastDay(startDate);
			$("#startDate").val(firstDate);
			$("#endDate").val(lastDate);
		});
		$("#btnDown").click(function() {
			layer.confirm('确认要导出出入库订单数据吗？', {
				btn : [ '确认', '取消' ]
			}, function() {
				$("#searchForm").attr("action", "${ctx}/report/bsReportPay/exportExcel2");
				$("#searchForm").submit();
				layer.msg('正在导出', {icon: 1});
				$("#searchForm").attr("action", "${ctx}/report/bsReportPay/bsReportPay");
			}, function() {
				
			});
		});
	});
	function page(n, s) {
		$("#pageNo").val(n);
		$("#pageSize").val(s);
		$("#searchForm").submit();
		return false;
	}

/* 	function setReceive(str, code, type, id, parentIds, grade) {
		$("#areaName").val(str);
		$("#areaCode").val(code);
	} */
	
	function rese() {//重置
		$("#startDate").val("");
		$("#endDate").val("");
		$("#areaName").val("");
		$("#areaCodeId").val("");
		$("#areaCodeName").val("");
	}
</script>
<style type="text/css">
#contentTable th {
	text-align: center;
}
</style>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/report/bsReportPay/bsReportPay">出入库金额统计</a></li>
	</ul>
	<form:form id="searchForm" modelAttribute="bsReportPay" action="${ctx}/report/bsReportPay/bsReportPay" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}" />
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}" />
		<%-- <input id="areaCode" name="areaCode" type="hidden" value="${bsReportPay.areaCode}" /> --%>
		<table class="table table-bordered">
			<tr>
				<th>地区</th>
				<td>
					<sys:treeselect2 id="areaCode" name="areaCode" value="${bsReportPay.areaCode}" labelName="areaName" labelValue="${bsReportPay.areaName}"
					title="机构" url="/sys/office/treeData" extId="${office.id}" cssClass="input-medium" allowClear="${office.currentUser.admin}" layer = "true"/>
					<%-- <input type="text" id="areaName" name="areaName" maxlength="255" readonly="true"
						class="input-medium" value="${bsReportPay.areaName}" /> 
					<input id="area" class="btn btn-primary btn-mini" type="button"
					value="选 择" /> --%>
					</td>
				<th>开始日期:</th>
				<td><input name="startDate" id="startDate" type="text"
					readonly="readonly" maxlength="20" class="input-medium Wdate"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});"
					value='<fmt:formatDate value='${bsReportPay.startDate}' pattern="yyyy-MM-dd" />' />
				</td>
				<th>截至日期:</th>
				<td><input name="endDate" id="endDate" type="text"
					readonly="readonly" maxlength="20" class="input-medium Wdate"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});"
					value='<fmt:formatDate value='${bsReportPay.endDate}' pattern="yyyy-MM-dd" />' />
				</td>
				<td colspan="2">
					<input type="button" class="btn btn-primary"  id="lastMonth"    value="上月"/>
					<input type="button" class="btn btn-primary"  id="thisMonth"    value="本月"/>
					<input type="button" class="btn btn-primary"  id="quarter"  value="本季度"/>
                    <input type="button" class="btn btn-primary"  id="thisYear" value="本年度"/>
				</td>
			</tr>
		</table>
		<div>
			<button id="btnSubmit" class="btn btn-primary" type="submit">查询</button>
			<button id="btnReset" class="btn btn-primary" type="button"
				onclick="rese()">重置</button>
			<button id="btnDown" class="btn btn-primary" type="button">导出</button>
		</div>
	</form:form>
	<sys:message content="${message}" />
	<table id="contentTable"
		class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th rowspan="3">收款单位</th>
				<th rowspan="3">欠款单位</th>
				<th rowspan="3">期初欠款</th>
				<th colspan="5">本期发生</th>
				<th rowspan="3">期末欠款</th>
			</tr>
			<tr>
				<th rowspan="2">本期欠款</th>
				<th rowspan="2">本期回款</th>
				<th colspan="3">账单明细</th>
			</tr>
			<tr>
				<th>类型</th>
				<!-- <th>欠款金额</th>
				<th>回款金额</th> -->
				<th>日期</th>
				<th>单号</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${list}" var="total">
				<c:if test="${total.num == 0}">
					<tr>
						<td>${total.supplyorgName}</td>
						<td>${total.receiveorgName}</td>
						<td>${total.qcqk}</td>
						<td></td> <td></td> <td></td>
						<td></td>
						<td></td>
						<td>${total.qmqk}</td>
					</tr>
				</c:if>
				<c:if test="${total.num > 0}">
				<c:forEach items="${detailList}" var="bsReportPay">
					<c:if test="${total.supplyorgCode== bsReportPay.supplyorgCode && total.receiveorgCode== bsReportPay.receiveorgCode}">
						<tr>
							<c:if test="${bsReportPay.num == 1}">
								<td>${total.supplyorgName}</td>
								<td>${total.receiveorgName}</td>
								<td>${total.qcqk}</td>
							</c:if>
							<c:if test="${bsReportPay.num != 1}"> <td></td> <td></td> <td></td> <!-- <td></td> <td></td> --> </c:if>
							<td><c:if test="${bsReportPay.payType == 1}">
								${bsReportPay.payment}
							</c:if></td>
							<td><c:if test="${bsReportPay.payType == 2 || bsReportPay.payType == 3}">
								-${bsReportPay.payment}
							</c:if></td>
							<td>${fns:getDictLabel(bsReportPay.type, "pay_order_type", "")}/${fns:getDictLabel(bsReportPay.payType, "pay_type", "")}</td>
							<td><fmt:formatDate value="${bsReportPay.payDate}" pattern="yyyy-MM-dd" /></td>
							<td>${bsReportPay.orderNo}</td>
							<c:if test="${bsReportPay.num == total.num}">
								<td>${total.qmqk}</td>
							</c:if>
							<c:if test="${bsReportPay.num != total.num}"> <td></td> </c:if>
						</tr>
					</c:if>
				</c:forEach>
				</c:if>
			</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>